﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YArchitech.Revit;
using YJKArchMethodLibrary.Utils;
using YJKRGeometry;
using StairsModuleAndEdit.StairsModel.CommonUnit;

namespace SectionSignAndFilled.StairsClearHeightDimension
{
	public class StairsClearHeightMgr
	{
		public StairsClearHeightMgr(Autodesk.Revit.DB.Document doc, ElementId viewId = null)
		{
			this.m_doc = doc;
			this.m_viewId = viewId;
			this.m_floorSearch = new FloorSearchManager(this.m_doc);
			this.m_dTol = YJKArchMethodLibrary.Utils.Common.MMToFeet(150.0);
		}

		private CurveArray GetTwoMaxArc(CurveArray arcCurves)
		{
			CurveArray curveArray = new CurveArray();
            Curve curve = arcCurves.get_Item(arcCurves.Size - 1);
			curveArray.Append(curve);
			XYZ xyz = curve.Tessellate().ElementAt(curve.Tessellate().Count / 2);
			Arc arc = curve as Arc;
			XYZ center = arc.Center;
			Line line = Line.CreateBound(center, xyz);
			IEnumerator enumerator = arcCurves.GetEnumerator();
			{
				if (enumerator.MoveNext())
				{
					Curve curve2 = (Curve)enumerator.Current;
					line.Intersect(curve2);
					curveArray.Append(curve2);
				}
			}
			return curveArray;
		}

		private Line CreateRunUnBoundLine(StairsRun sRun)
		{
			Line result = null;
			if (sRun != null)
			{
				CurveLoop footprintBoundary = sRun.GetFootprintBoundary();
				CurveLoopSplit curveLoopSplit = new CurveLoopSplit(footprintBoundary);
				bool flag = curveLoopSplit.HasTwoArcCurve();
				CurveLoopSplit.CurveType type = CurveLoopSplit.CurveType.CT_LINE;
				if (flag)
				{
					type = CurveLoopSplit.CurveType.CT_ARC;
					CurveArray twoMaxArc = this.GetTwoMaxArc(curveLoopSplit.GetSortCurves(type));
					if (twoMaxArc.Size >= 2)
					{
						XYZ ptStart = XYZ.Zero;
						XYZ ptEnd = XYZ.Zero;
						int size = twoMaxArc.Size;
                        Arc arc = twoMaxArc.get_Item(size - 2) as Arc;
						XYZ endPoint = arc.GetEndPoint(0);
						XYZ endPoint2 = arc.GetEndPoint(1);
						XYZ center = arc.Center;
						if (arc != null)
						{
							ptStart = StairsModuleAndEdit.StairsModel.CommonUnit.Geometry.CalculatMidPoint(endPoint, endPoint2, center, arc.Normal);
						}
						arc = (twoMaxArc.get_Item(size - 1) as Arc);
						endPoint = arc.GetEndPoint(0);
						endPoint2 = arc.GetEndPoint(1);
						center = arc.Center;
						if (arc != null)
						{
							ptEnd = StairsModuleAndEdit.StairsModel.CommonUnit.Geometry.CalculatMidPoint(endPoint, endPoint2, center, arc.Normal);
						}
						XYZ xyz = StairsModuleAndEdit.StairsModel.CommonUnit.Geometry.CalculatMidPoint(ptStart, ptEnd);
						result = Line.CreateUnbound(xyz, XYZ.BasisZ);
					}
				}
				else
				{
					List<XYZ> curvesPoint = curveLoopSplit.GetCurvesPoint(type);
					if (curvesPoint.Count >= 2)
					{
						XYZ xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(curvesPoint);
						result = Line.CreateUnbound(xyz, XYZ.BasisZ);
					}
				}
			}
			return result;
		}

		private Line CreateLandUnBoundLine(StairsLanding sLand)
		{
			Line result = null;
			if (sLand != null)
			{
				CurveLoop footprintBoundary = sLand.GetFootprintBoundary();
				CurveLoopSplit curveLoopSplit = new CurveLoopSplit(footprintBoundary);
				CurveLoopSplit.CurveType type = CurveLoopSplit.CurveType.CT_LINE;
				List<XYZ> curvesPoint = curveLoopSplit.GetCurvesPoint(type);
				if (curvesPoint.Count >= 2)
				{
					XYZ xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(curvesPoint);
					result = Line.CreateUnbound(xyz, XYZ.BasisZ);
				}
			}
			return result;
		}

		private List<StairsRun> GetStairsAllRun(Stairs stairs)
		{
			List<StairsRun> list = new List<StairsRun>();
			if (stairs != null)
			{
				ICollection<ElementId> stairsRuns = stairs.GetStairsRuns();
				foreach (ElementId elementId in stairsRuns)
				{
					StairsRun stairsRun = this.m_doc.GetElement(elementId) as StairsRun;
					if (stairsRun != null)
					{
						list.Add(stairsRun);
					}
				}
			}
			return list;
		}

		private List<StairsLanding> GetStairsAllLand(Stairs stairs)
		{
			List<StairsLanding> list = new List<StairsLanding>();
			if (stairs != null)
			{
				ICollection<ElementId> stairsLandings = stairs.GetStairsLandings();
				foreach (ElementId elementId in stairsLandings)
				{
					StairsLanding stairsLanding = this.m_doc.GetElement(elementId) as StairsLanding;
					if (stairsLanding != null)
					{
						list.Add(stairsLanding);
					}
				}
			}
			return list;
		}

		private Line ViewSectionToCutLine(ViewSection view)
		{
			Line result = null;
			if (view != null)
			{
				XYZ xyz = new XYZ(view.Origin.X, view.Origin.Y, 0.0);
				result = Line.CreateUnbound(xyz, view.RightDirection);
			}
			return result;
		}

		private List<Line> DistinctLines(List<Line> arSrcLine)
		{
			List<Line> list = new List<Line>();
			int count = arSrcLine.Count;
			for (int i = 0; i < count; i++)
			{
				Line line = arSrcLine[i];
				XYZ origin = line.Origin;
				bool flag = false;
				for (int j = 0; j < list.Count; j++)
				{
					XYZ origin2 = arSrcLine[j].Origin;
					double num = origin.DistanceTo(origin2);
					if (num < YJKArchMethodLibrary.Utils.Common.MMToFeet(50.0))
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					list.Add(line);
				}
			}
			return list;
		}

		private List<Line> CreateStairsRunLines(Stairs stairs)
		{
			List<Line> list = new List<Line>();
			if (stairs != null)
			{
				ICollection<ElementId> stairsRuns = stairs.GetStairsRuns();
				if (this.m_initDataType == StairsClearHeightMgr.InitDataType.INIT_CHKCLEARHEIGHT)
				{
					IEnumerator<ElementId> enumerator = stairsRuns.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							ElementId elementId = enumerator.Current;
							StairsRun sRun = this.m_doc.GetElement(elementId) as StairsRun;
							Line line = this.CreateRunUnBoundLine(sRun);
							if (null != line)
							{
								list.Add(line);
							}
						}
						goto IL_1B0;
					}
				}
				if (this.m_initDataType == StairsClearHeightMgr.InitDataType.INIT_DMSCLEARHEIGHT)
				{
					ViewSection viewSection = this.m_doc.GetElement(this.m_viewId) as ViewSection;
					if (viewSection != null)
					{
						Line curve = this.ViewSectionToCutLine(viewSection);
						foreach (ElementId elementId2 in stairsRuns)
						{
							StairsRun stairsRun = this.m_doc.GetElement(elementId2) as StairsRun;
							CurveLoop footprintBoundary = stairsRun.GetFootprintBoundary();
							List<XYZ> list2 = CurveLoopSplit.GetCurveToLoopIntersection(curve, footprintBoundary);
							list2 = StairsClearHeightDimensionGeometry.SortPointsWithVector(list2, viewSection.RightDirection);
							int count = list2.Count;
							if (count > 0)
							{
								if (count == 1)
								{
									XYZ xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(list2);
									Line line2 = Line.CreateUnbound(xyz, XYZ.BasisZ);
									if (null != line2)
									{
										list.Add(line2);
									}
								}
								else
								{
									for (int i = 0; i < count - 1; i++)
									{
										XYZ xyz2 = list2[i];
										XYZ xyz3 = list2[i + 1];
										if (xyz2 != null && xyz3 != null)
										{
											XYZ xyz4 = YJKArchMethodLibrary.Utils.Geometry.CalculatMidPoint(xyz2, xyz3);
											Line line3 = Line.CreateUnbound(xyz4, XYZ.BasisZ);
											if (null != line3)
											{
												list.Add(line3);
											}
										}
									}
								}
							}
						}
					}
				}
			}
			IL_1B0:
			return this.DistinctLines(list);
		}

		private List<Line> CreateStairsLandLines(Stairs stairs)
		{
			List<Line> list = new List<Line>();
			if (stairs != null)
			{
				ICollection<ElementId> stairsLandings = stairs.GetStairsLandings();
				if (this.m_initDataType == StairsClearHeightMgr.InitDataType.INIT_CHKCLEARHEIGHT)
				{
					IEnumerator<ElementId> enumerator = stairsLandings.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							ElementId elementId = enumerator.Current;
							StairsLanding sLand = this.m_doc.GetElement(elementId) as StairsLanding;
							Line line = this.CreateLandUnBoundLine(sLand);
							if (null != line)
							{
								list.Add(line);
							}
						}
						goto IL_12E;
					}
				}
				if (this.m_initDataType == StairsClearHeightMgr.InitDataType.INIT_DMSCLEARHEIGHT)
				{
					ViewSection viewSection = this.m_doc.GetElement(this.m_viewId) as ViewSection;
					if (viewSection != null)
					{
						Line curve = this.ViewSectionToCutLine(viewSection);
						foreach (ElementId elementId2 in stairsLandings)
						{
							StairsLanding stairsLanding = this.m_doc.GetElement(elementId2) as StairsLanding;
							CurveLoop footprintBoundary = stairsLanding.GetFootprintBoundary();
							List<XYZ> curveToLoopIntersection = CurveLoopSplit.GetCurveToLoopIntersection(curve, footprintBoundary);
							if (curveToLoopIntersection.Count > 0)
							{
								XYZ xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(curveToLoopIntersection);
								Line line2 = Line.CreateUnbound(xyz, XYZ.BasisZ);
								if (null != line2)
								{
									list.Add(line2);
								}
							}
						}
					}
				}
			}
			IL_12E:
			return this.DistinctLines(list);
		}

		private bool GetIntersectionMaxMinPoint(Element element, Line unBoundLine, out XYZ ptMin, out XYZ ptMax)
		{
			bool result = false;
			CurveIntersection curveIntersection = new CurveIntersection(element, unBoundLine);
			List<XYZ> stairsRunLandSortedPoints = curveIntersection.GetStairsRunLandSortedPoints(CurveIntersection.IntersectionType.IT_SOLID);
			XYZ xyz = null;
			XYZ xyz2 = null;
			if (stairsRunLandSortedPoints.Count > 0)
			{
				result = true;
				xyz = stairsRunLandSortedPoints.First<XYZ>();
				xyz2 = stairsRunLandSortedPoints.Last<XYZ>();
			}
			ptMin = xyz;
			ptMax = xyz2;
			return result;
		}

		private List<StairsClearHeightMgr.IntersectionData> GetLineIntersectionStairsRunArr(Line line, int nLineIndex, List<ElementId> arStairsId)
		{
			List<StairsClearHeightMgr.IntersectionData> list = new List<StairsClearHeightMgr.IntersectionData>();
			foreach (ElementId elementId in arStairsId)
			{
				Stairs stairs = this.m_doc.GetElement(elementId) as Stairs;
				if (stairs != null)
				{
					List<StairsRun> stairsAllRun = this.GetStairsAllRun(stairs);
					foreach (StairsRun stairsRun in stairsAllRun)
					{
						XYZ ptMax = null;
						XYZ ptMin = null;
						if (this.GetIntersectionMaxMinPoint(stairsRun, line, out ptMin, out ptMax))
						{
							StairsClearHeightMgr.MaxMinPoint point = new StairsClearHeightMgr.MaxMinPoint(ptMin, ptMax);
							StairsClearHeightMgr.IntersectionData item = new StairsClearHeightMgr.IntersectionData(stairs.Id, stairsRun.Id, point, nLineIndex);
							list.Add(item);
						}
					}
				}
			}
			return list;
		}

		private List<StairsClearHeightMgr.IntersectionData> GetLineIntersectionStairsLandArr(Line line, int nLineIndex, List<ElementId> arStairsId)
		{
			List<StairsClearHeightMgr.IntersectionData> list = new List<StairsClearHeightMgr.IntersectionData>();
			foreach (ElementId elementId in arStairsId)
			{
				Stairs stairs = this.m_doc.GetElement(elementId) as Stairs;
				if (stairs != null)
				{
					List<StairsLanding> stairsAllLand = this.GetStairsAllLand(stairs);
					foreach (StairsLanding stairsLanding in stairsAllLand)
					{
						XYZ ptMax = null;
						XYZ ptMin = null;
						if (this.GetIntersectionMaxMinPoint(stairsLanding, line, out ptMin, out ptMax))
						{
							StairsClearHeightMgr.MaxMinPoint point = new StairsClearHeightMgr.MaxMinPoint(ptMin, ptMax);
							StairsClearHeightMgr.IntersectionData item = new StairsClearHeightMgr.IntersectionData(stairs.Id, stairsLanding.Id, point, nLineIndex);
							list.Add(item);
						}
					}
				}
			}
			return list;
		}

		private List<StairsClearHeightMgr.IntersectionData> CreateLinesRunIntersection(List<Line> arRunLines, List<ElementId> arStairsId)
		{
			List<StairsClearHeightMgr.IntersectionData> list = new List<StairsClearHeightMgr.IntersectionData>();
			if (arRunLines != null)
			{
				int num = 0;
				foreach (Line line in arRunLines)
				{
					list.AddRange(this.GetLineIntersectionStairsRunArr(line, num++, arStairsId));
				}
			}
			return list;
		}

		private List<List<StairsClearHeightMgr.IntersectionData>> CreateLinesLandIntersection(List<Line> arLandLines, List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.IntersectionData>> list = new List<List<StairsClearHeightMgr.IntersectionData>>();
			if (arLandLines != null)
			{
				int num = 0;
				foreach (Line line in arLandLines)
				{
					List<StairsClearHeightMgr.IntersectionData> list2 = new List<StairsClearHeightMgr.IntersectionData>();
					list2.AddRange(this.GetLineIntersectionStairsLandArr(line, num++, arStairsId));
					list.Add(list2);
				}
			}
			return list;
		}

		private List<List<StairsClearHeightMgr.IntersectionData>> GetStairsRunAllIntersection(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.IntersectionData>> list = new List<List<StairsClearHeightMgr.IntersectionData>>();
			List<ElementId> list2 = new List<ElementId>();
			list2.AddRange(arStairsId);
			while (list2.Count > 0)
			{
				Stairs stairs = this.m_doc.GetElement(list2[0]) as Stairs;
				if (stairs != null)
				{
					List<Line> list3 = this.CreateStairsRunLines(stairs);
					if (list3.Count == 0)
					{
						list2.RemoveAt(0);
					}
					else
					{
						List<StairsClearHeightMgr.IntersectionData> list4 = this.CreateLinesRunIntersection(list3, list2);
						if (list4.Count > 0)
						{
							list.Add(list4);
							using (List<StairsClearHeightMgr.IntersectionData>.Enumerator enumerator = list4.GetEnumerator())
							{
								while (enumerator.MoveNext())
								{
									StairsClearHeightMgr.IntersectionData intersectionData = enumerator.Current;
									ElementId stairsId = intersectionData.m_StairsId;
									list2.Remove(stairsId);
								}
								continue;
							}
						}
						list2.RemoveAt(0);
					}
				}
				else
				{
					list2.RemoveAt(0);
				}
			}
			return list;
		}

		private List<List<StairsClearHeightMgr.IntersectionData>> GetStairsLandAllIntersection(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.IntersectionData>> result = new List<List<StairsClearHeightMgr.IntersectionData>>();
			List<ElementId> list = new List<ElementId>();
			list.AddRange(arStairsId);
			while (list.Count > 0)
			{
				Stairs stairs = this.m_doc.GetElement(list[0]) as Stairs;
				if (stairs != null)
				{
					List<Line> list2 = this.CreateStairsLandLines(stairs);
					if (list2.Count == 0)
					{
						list.RemoveAt(0);
					}
					else
					{
						List<List<StairsClearHeightMgr.IntersectionData>> list3 = this.CreateLinesLandIntersection(list2, list);
						if (list3.Count > 0)
						{
							result = list3;
							using (List<List<StairsClearHeightMgr.IntersectionData>>.Enumerator enumerator = list3.GetEnumerator())
							{
								while (enumerator.MoveNext())
								{
									List<StairsClearHeightMgr.IntersectionData> list4 = enumerator.Current;
									foreach (StairsClearHeightMgr.IntersectionData intersectionData in list4)
									{
										ElementId stairsId = intersectionData.m_StairsId;
										list.Remove(stairsId);
									}
								}
								continue;
							}
						}
						list.RemoveAt(0);
					}
				}
				else
				{
					list.RemoveAt(0);
				}
			}
			return result;
		}

		private List<StairsClearHeightMgr.ClearHeightData> GetOneGroupRunClearHeigthData(List<StairsClearHeightMgr.IntersectionData> arInterSecData)
		{
			List<StairsClearHeightMgr.ClearHeightData> list = new List<StairsClearHeightMgr.ClearHeightData>();
			Dictionary<ElementId, List<StairsClearHeightMgr.IntersectionData>> dictionary = new Dictionary<ElementId, List<StairsClearHeightMgr.IntersectionData>>();
			foreach (StairsClearHeightMgr.IntersectionData intersectionData in arInterSecData)
			{
				ElementId stairsId = intersectionData.m_StairsId;
				if (!dictionary.ContainsKey(stairsId))
				{
					dictionary.Add(stairsId, new List<StairsClearHeightMgr.IntersectionData>
					{
						intersectionData
					});
				}
				else
				{
					dictionary[stairsId].Add(intersectionData);
				}
			}
			if (dictionary.Count > 0)
			{
				foreach (KeyValuePair<ElementId, List<StairsClearHeightMgr.IntersectionData>> keyValuePair in dictionary)
				{
					StairsClearHeightMgr.ClearHeightData item = new StairsClearHeightMgr.ClearHeightData(keyValuePair.Key, keyValuePair.Value);
					list.Add(item);
				}
			}
			return list;
		}

		private List<StairsClearHeightMgr.ClearHeightData> SortOneClearHeightData(List<StairsClearHeightMgr.ClearHeightData> arClearHData)
		{
			List<StairsClearHeightMgr.ClearHeightData> list = new List<StairsClearHeightMgr.ClearHeightData>();
			if (arClearHData.Count == 1)
			{
				return arClearHData;
			}
			SortedDictionary<double, List<StairsClearHeightMgr.ClearHeightData>> sortedDictionary = new SortedDictionary<double, List<StairsClearHeightMgr.ClearHeightData>>();
			foreach (StairsClearHeightMgr.ClearHeightData clearHeightData in arClearHData)
			{
				double clearHDataMinZValue = clearHeightData.GetClearHDataMinZValue();
				if (!sortedDictionary.ContainsKey(clearHDataMinZValue))
				{
					sortedDictionary.Add(clearHDataMinZValue, new List<StairsClearHeightMgr.ClearHeightData>
					{
						clearHeightData
					});
				}
				else
				{
					sortedDictionary[clearHDataMinZValue].Add(clearHeightData);
				}
			}
			foreach (KeyValuePair<double, List<StairsClearHeightMgr.ClearHeightData>> keyValuePair in sortedDictionary)
			{
				list.AddRange(keyValuePair.Value);
			}
			return list;
		}

		private List<List<StairsClearHeightMgr.ClearHeightData>> GetStarisRunAllClearHData(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.ClearHeightData>> list = new List<List<StairsClearHeightMgr.ClearHeightData>>();
			List<List<StairsClearHeightMgr.IntersectionData>> stairsRunAllIntersection = this.GetStairsRunAllIntersection(arStairsId);
			foreach (List<StairsClearHeightMgr.IntersectionData> arInterSecData in stairsRunAllIntersection)
			{
				List<StairsClearHeightMgr.ClearHeightData> oneGroupRunClearHeigthData = this.GetOneGroupRunClearHeigthData(arInterSecData);
				List<StairsClearHeightMgr.ClearHeightData> list2 = this.SortOneClearHeightData(oneGroupRunClearHeigthData);
				if (list2.Count > 0)
				{
					list.Add(list2);
				}
			}
			return list;
		}

		private List<List<StairsClearHeightMgr.ClearHeightData>> GetStarisLandAllClearHData(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.ClearHeightData>> list = new List<List<StairsClearHeightMgr.ClearHeightData>>();
			List<List<StairsClearHeightMgr.IntersectionData>> stairsLandAllIntersection = this.GetStairsLandAllIntersection(arStairsId);
			foreach (List<StairsClearHeightMgr.IntersectionData> arInterSecData in stairsLandAllIntersection)
			{
				List<StairsClearHeightMgr.ClearHeightData> oneGroupRunClearHeigthData = this.GetOneGroupRunClearHeigthData(arInterSecData);
				List<StairsClearHeightMgr.ClearHeightData> list2 = this.SortOneClearHeightData(oneGroupRunClearHeigthData);
				if (list2.Count > 0)
				{
					list.Add(list2);
				}
			}
			return list;
		}

		private List<Element> GetOneViewAllStairs()
		{
			List<Element> result = new List<Element>();
			if (null != this.m_viewId)
			{
				ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs);
				ElementCategoryFilter elementCategoryFilter2 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
				LogicalOrFilter filter = new LogicalOrFilter(elementCategoryFilter, elementCategoryFilter2);
				result = FloorSearchManager.FilterElemByKind(filter, this.m_doc);
			}
			return result;
		}

		private List<ElementId> GetStairsIds(List<Element> arStairs)
		{
			List<ElementId> list = new List<ElementId>();
			foreach (Element element in arStairs)
			{
				list.Add(element.Id);
			}
			return list;
		}

		private double GetStairsBeamDepth(ElementId landId)
		{
			double result = 0.0;
			StairsLanding stairsLanding = this.m_doc.GetElement(landId) as StairsLanding;
			if (stairsLanding != null)
			{
				Stairs stairs = stairsLanding.GetStairs();
				if (stairs != null)
				{
					bool flag = ElementXDataManager.StairsHasXDataGuid(stairs);
					if (flag)
					{
						string sStairsBeam = ElementXDataManager.m_sStairsBeam;
						List<ElementId> list = ElementXDataManager.ReadStairsBeamXData(stairs, sStairsBeam);
						if (list != null && list.Count > 0)
						{
							ElementId elementId = list.First<ElementId>();
							FamilyInstance familyInstance = this.m_doc.GetElement(elementId) as FamilyInstance;
							if (familyInstance != null)
							{
								result = familyInstance.Symbol.GetParameter("h").AsDouble();
							}
						}
					}
					else
					{
						FamilyInstance landBeam = this.GetLandBeam(stairsLanding);
						if (landBeam != null)
						{
							result = this.GetBeamHeight(landBeam);
						}
					}
				}
			}
			return result;
		}

		private List<FamilyInstance> GetViewSectionAllBeams(ElementId viewId, Document doc)
		{
			List<FamilyInstance> list = new List<FamilyInstance>();
			if (null != viewId && doc != null)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, viewId);
				filteredElementCollector.OfClass(typeof(FamilyInstance));
				filteredElementCollector.OfCategory(BuiltInCategory.OST_StructuralFraming);
				List<Element> list2 = filteredElementCollector.ToElements().ToList<Element>();
				foreach (Element element in list2)
				{
					FamilyInstance familyInstance = element as FamilyInstance;
					if (familyInstance != null)
					{
						list.Add(familyInstance);
					}
				}
			}
			return list;
		}

		private double GetDimLandBeamsDepth(ElementId landId, out XYZ ptMostBtm, out FamilyInstance famBeam)
		{
			double num = 0.0;
			ptMostBtm = null;
			famBeam = null;
			StairsLanding stairsLanding = this.m_doc.GetElement(landId) as StairsLanding;
			if (stairsLanding != null)
			{
				Stairs stairs = stairsLanding.GetStairs();
				if (stairs != null)
				{
					List<FamilyInstance> list = new List<FamilyInstance>();
					list = this.GetEqualLevelLandBeams(stairsLanding);
					List<FamilyInstance> viewSectionAllBeams = this.GetViewSectionAllBeams(this.m_viewId, this.m_doc);
					List<FamilyInstance> list2 = new List<FamilyInstance>();
					foreach (FamilyInstance familyInstance in list)
					{
						foreach (FamilyInstance familyInstance2 in viewSectionAllBeams)
						{
							if (familyInstance.Id.Equals(familyInstance2.Id))
							{
								list2.Add(familyInstance);
								break;
							}
						}
					}
					FamilyInstance maxHeightBeam = this.GetMaxHeightBeam(list2);
					if (maxHeightBeam != null)
					{
						num = this.GetBeamHeight(maxHeightBeam);
						XYZ beamCenter = this.GetBeamCenter(maxHeightBeam);
						XYZ xyz = new XYZ(0.0, 0.0, -num);
						ptMostBtm = beamCenter.Add(xyz);
						famBeam = maxHeightBeam;
					}
				}
			}
			return num;
		}

		private double GetStairsLandThickness(ElementId landId)
		{
			double result = 0.0;
			StairsLanding stairsLanding = this.m_doc.GetElement(landId) as StairsLanding;
			if (stairsLanding != null)
			{
				result = stairsLanding.Thickness;
			}
			return result;
		}

		private bool IsMoreLevelStairs(ElementId stairsId)
		{
			bool result = false;
			Stairs stairs = this.m_doc.GetElement(stairsId) as Stairs;
			if (stairs != null && stairs.GetParameter("多层顶部标高") != null)
			{
				ElementId elementId = stairs.GetParameter("多层顶部标高").AsElementId();
				if (null != elementId && elementId.IntegerValue != -1)
				{
					result = true;
				}
			}
			return result;
		}

		private void InitCheckClearHeightData(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.ClearHeightData>> starisRunAllClearHData = this.GetStarisRunAllClearHData(arStairsId);
			List<List<StairsClearHeightMgr.ClearHeightData>> starisLandAllClearHData = this.GetStarisLandAllClearHData(arStairsId);
			this.m_checkData.Add(StairsClearHeightMgr.CheckType.CT_SRUN, starisRunAllClearHData);
			this.m_checkData.Add(StairsClearHeightMgr.CheckType.CT_SLAND, starisLandAllClearHData);
		}

		private void InitDimensionClearHeightData(List<ElementId> arStairsId)
		{
			List<List<StairsClearHeightMgr.ClearHeightData>> starisRunAllClearHData = this.GetStarisRunAllClearHData(arStairsId);
			List<List<StairsClearHeightMgr.ClearHeightData>> starisLandAllClearHData = this.GetStarisLandAllClearHData(arStairsId);
			this.m_dimensionData.Add(StairsClearHeightMgr.DimObjType.DOT_RUN, starisRunAllClearHData);
			this.m_dimensionData.Add(StairsClearHeightMgr.DimObjType.DOT_LAND, starisLandAllClearHData);
		}

		private Solid CreateStairsLandSolid(StairsLanding sLand)
		{
			Solid result = null;
			try
			{
				if (sLand != null)
				{
					CurveLoop footprintBoundary = sLand.GetFootprintBoundary();
					List<CurveLoop> list = new List<CurveLoop>();
					list.Add(footprintBoundary);
					Stairs stairs = sLand.GetStairs();
					if (footprintBoundary != null && stairs != null)
					{
						double num = Math.Abs(stairs.TopElevation);
						result = GeometryCreationUtilities.CreateExtrusionGeometry(list, XYZ.BasisZ, num);
					}
				}
			}
			catch (Exception)
			{
				return null;
			}
			return result;
		}

		private Dictionary<double, List<FamilyInstance>> GetLandDicBeams(StairsLanding sLand)
		{
			Dictionary<double, List<FamilyInstance>> dictionary = new Dictionary<double, List<FamilyInstance>>();
			if (sLand != null)
			{
				Document document = sLand.Document;
				Solid solid = this.CreateStairsLandSolid(sLand);
				if (document != null && null != solid)
				{
					FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
					filteredElementCollector.OfCategory(BuiltInCategory.OST_StructuralFraming);
					ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(solid);
					List<Element> list = filteredElementCollector.WherePasses(elementIntersectsSolidFilter).ToElements().ToList<Element>();
					foreach (Element element in list)
					{
						FamilyInstance familyInstance = element as FamilyInstance;
						if (familyInstance != null)
						{
							double beamLocationZValue = this.GetBeamLocationZValue(familyInstance);
							if (!dictionary.ContainsKey(beamLocationZValue))
							{
								dictionary.Add(beamLocationZValue, new List<FamilyInstance>
								{
									familyInstance
								});
							}
							else
							{
								dictionary[beamLocationZValue].Add(familyInstance);
							}
						}
					}
				}
			}
			return dictionary;
		}

		private Dictionary<double, List<FamilyInstance>> GetRangeDicBeams(List<CurveLoop> lstLoop, double dStretchDis, XYZ vecStretchDir)
		{
			Dictionary<double, List<FamilyInstance>> dictionary = new Dictionary<double, List<FamilyInstance>>();
			Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(lstLoop, vecStretchDir, dStretchDis);
			if (null != solid)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_doc);
				filteredElementCollector.OfCategory(BuiltInCategory.OST_StructuralFraming);
				ElementIntersectsSolidFilter elementIntersectsSolidFilter = new ElementIntersectsSolidFilter(solid);
				List<Element> list = filteredElementCollector.WherePasses(elementIntersectsSolidFilter).ToElements().ToList<Element>();
				foreach (Element element in list)
				{
					FamilyInstance familyInstance = element as FamilyInstance;
					if (familyInstance != null)
					{
						double beamLocationZValue = this.GetBeamLocationZValue(familyInstance);
						if (!dictionary.ContainsKey(beamLocationZValue))
						{
							dictionary.Add(beamLocationZValue, new List<FamilyInstance>
							{
								familyInstance
							});
						}
						else
						{
							dictionary[beamLocationZValue].Add(familyInstance);
						}
					}
				}
			}
			return dictionary;
		}

		private FamilyInstance GetMaxHeightBeam(List<FamilyInstance> arBeams)
		{
			FamilyInstance result = null;
			double num = double.MinValue;
			foreach (FamilyInstance familyInstance in arBeams)
			{
				if (familyInstance != null)
				{
					double beamHeight = this.GetBeamHeight(familyInstance);
					if (beamHeight > num)
					{
						num = beamHeight;
						result = familyInstance;
					}
				}
			}
			return result;
		}

		private FamilyInstance GetLandBeam(StairsLanding sLand)
		{
			FamilyInstance result = null;
			if (sLand != null)
			{
				List<FamilyInstance> equalLevelLandBeams = this.GetEqualLevelLandBeams(sLand);
				if (equalLevelLandBeams != null)
				{
					result = this.GetMaxHeightBeam(equalLevelLandBeams);
				}
			}
			return result;
		}

		private FamilyInstance GetMoreLevelLandBeam(StairsLanding baseLand, double dLoopHeight, double dBeamHeight, double dStretchDis, XYZ vecStretchDir)
		{
			FamilyInstance result = null;
			CurveLoop footprintBoundary = baseLand.GetFootprintBoundary();
			double z = footprintBoundary.ElementAt(0).GetEndPoint(0).Z;
			XYZ xyz = new XYZ(0.0, 0.0, dLoopHeight - z);
			List<CurveLoop> list = new List<CurveLoop>();
			Transform transform = Transform.CreateTranslation(xyz);
			list.Add(CurveLoop.CreateViaTransform(footprintBoundary, transform));
			Dictionary<double, List<FamilyInstance>> rangeDicBeams = this.GetRangeDicBeams(list, dStretchDis, vecStretchDir);
			double num = StairsLandingParamManager.GetLandThickness(baseLand) + 0.0001;
			foreach (KeyValuePair<double, List<FamilyInstance>> keyValuePair in rangeDicBeams)
			{
				if (Math.Abs(keyValuePair.Key - dBeamHeight) < num)
				{
					result = this.GetMaxHeightBeam(keyValuePair.Value);
					break;
				}
			}
			return result;
		}

		private List<FamilyInstance> GetEqualLevelLandBeams(StairsLanding sLand)
		{
			List<FamilyInstance> list = new List<FamilyInstance>();
			if (sLand != null)
			{
				Dictionary<double, List<FamilyInstance>> landDicBeams = this.GetLandDicBeams(sLand);
				double num = StairsLandingParamManager.GetLandThickness(sLand) + 0.0001;
				double absoluteElevation = StairsLandingParamManager.GetAbsoluteElevation(sLand);
				foreach (KeyValuePair<double, List<FamilyInstance>> keyValuePair in landDicBeams)
				{
					if (Math.Abs(keyValuePair.Key - absoluteElevation) < num)
					{
						list.AddRange(keyValuePair.Value);
						break;
					}
				}
			}
			return list;
		}

		private bool IsRunConnectLand(StairsRun sBtmRun, StairsRun sTopRun, double dTol, bool bIsBottom = true)
		{
			bool flag = false;
			if (sBtmRun != null && sTopRun != null)
			{
				Stairs stairs = sBtmRun.GetStairs();
				Stairs stairs2 = sTopRun.GetStairs();
				if (stairs != null && stairs2 != null)
				{
					double num = StairsRunParamManager.GetAbsoluteBaseElevation(sTopRun);
					double num2 = StairsRunParamManager.GetAbsoluteBaseElevation(sBtmRun);
					if (!bIsBottom)
					{
						num = StairsRunParamManager.GetAbsoluteTopElevation(sTopRun);
						num2 = StairsRunParamManager.GetAbsoluteTopElevation(sBtmRun);
					}
					List<StairsLanding> stairsAllLand = this.GetStairsAllLand(stairs);
					List<StairsLanding> stairsAllLand2 = this.GetStairsAllLand(stairs2);
					List<StairsLanding> list = new List<StairsLanding>();
					list.AddRange(stairsAllLand);
					list.AddRange(stairsAllLand2);
					foreach (StairsLanding landing in list)
					{
						double absoluteElevation = StairsLandingParamManager.GetAbsoluteElevation(landing);
						if (Math.Abs(num - absoluteElevation) < 1E-05)
						{
							flag = true;
							break;
						}
					}
					if (!flag)
					{
						foreach (StairsLanding landing2 in list)
						{
							double absoluteElevation2 = StairsLandingParamManager.GetAbsoluteElevation(landing2);
							if (Math.Abs(num2 - absoluteElevation2) < 1E-05)
							{
								flag = true;
								break;
							}
						}
					}
				}
			}
			return flag;
		}

		private double GetBeamLocationZValue(Element ele)
		{
			double result = 0.0;
			if (ele != null)
			{
				Location location = ele.Location;
				if (location != null)
				{
					Type type = location.GetType();
					if (type == typeof(LocationPoint))
					{
						LocationPoint locationPoint = location as LocationPoint;
						if (locationPoint != null)
						{
							XYZ point = locationPoint.Point;
							if (point != null)
							{
								result = point.Z;
							}
						}
					}
					else if (type == typeof(LocationCurve))
					{
						BeamGeometryManager beamGeometryManager = new BeamGeometryManager(ele as FamilyInstance);
						Curve beamRealLocationCurve = beamGeometryManager.GetBeamRealLocationCurve();
						if (null != beamRealLocationCurve)
						{
							XYZ endPoint = beamRealLocationCurve.GetEndPoint(0);
							if (endPoint != null)
							{
								result = endPoint.Z;
							}
						}
					}
				}
			}
			return result;
		}

		private Dictionary<double, List<FamilyInstance>> GetStairsBeamInstance(StairsRun sRun)
		{
			Dictionary<double, List<FamilyInstance>> dictionary = new Dictionary<double, List<FamilyInstance>>();
			if (sRun != null)
			{
				Stairs stairs = sRun.GetStairs();
				if (stairs != null)
				{
					string sStairsBeam = ElementXDataManager.m_sStairsBeam;
					List<ElementId> list = ElementXDataManager.ReadStairsBeamXData(stairs, sStairsBeam);
					foreach (ElementId elementId in list)
					{
						FamilyInstance familyInstance = sRun.Document.GetElement(elementId) as FamilyInstance;
						if (familyInstance != null)
						{
							LocationCurve locationCurve = familyInstance.Location as LocationCurve;
							if (locationCurve != null)
							{
								BeamGeometryManager beamGeometryManager = new BeamGeometryManager(familyInstance);
								Curve beamRealLocationCurve = beamGeometryManager.GetBeamRealLocationCurve();
								if (null != beamRealLocationCurve)
								{
									XYZ endPoint = beamRealLocationCurve.GetEndPoint(0);
									if (endPoint != null)
									{
										double z = endPoint.Z;
										if (!dictionary.ContainsKey(z))
										{
											dictionary.Add(z, new List<FamilyInstance>
											{
												familyInstance
											});
										}
										else
										{
											dictionary[z].Add(familyInstance);
										}
									}
								}
							}
						}
					}
				}
			}
			return dictionary;
		}

		private Dictionary<double, List<FamilyInstance>> GetDocumentAllBeams(Autodesk.Revit.DB.Document doc)
		{
			Dictionary<double, List<FamilyInstance>> dictionary = new Dictionary<double, List<FamilyInstance>>();
			if (doc != null)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				List<Element> list = filteredElementCollector.OfCategory(BuiltInCategory.OST_StructuralFraming).OfClass(typeof(FamilyInstance)).ToList<Element>();
				foreach (Element element in list)
				{
					FamilyInstance familyInstance = element as FamilyInstance;
					if (familyInstance != null)
					{
						double beamLocationZValue = this.GetBeamLocationZValue(familyInstance);
						if (!dictionary.ContainsKey(beamLocationZValue))
						{
							dictionary.Add(beamLocationZValue, new List<FamilyInstance>
							{
								familyInstance
							});
						}
						else
						{
							dictionary[beamLocationZValue].Add(familyInstance);
						}
					}
				}
			}
			return dictionary;
		}

		private Line GetLineToOneSide(StairsRun sRun, bool bIsBottom = true)
		{
			Line result = null;
			XYZ xyz = -this.GetStairsRunPath(sRun);
			if (!bIsBottom)
			{
				xyz = -xyz;
			}
			XYZ stairsRunTreadOutLineCenter = this.GetStairsRunTreadOutLineCenter(sRun, bIsBottom);
			if (stairsRunTreadOutLineCenter != null)
			{
				double dRunTransValue = this.m_dRunTransValue;
				XYZ xyz2 = stairsRunTreadOutLineCenter + xyz.Multiply(dRunTransValue);
				result = Line.CreateBound(stairsRunTreadOutLineCenter, xyz2);
			}
			return result;
		}

		private Line GetOppositeLine(Line line)
		{
			Line result = null;
			if (null != line)
			{
				XYZ origin = line.Origin;
				double length = line.Length;
				XYZ xyz = -line.Direction.Multiply(length);
				XYZ xyz2 = origin.Add(xyz);
				result = Line.CreateBound(origin, xyz2);
			}
			return result;
		}

		private FamilyInstance GetMostNearToTreadBeam(Line lineDir, List<FamilyInstance> arBeams)
		{
			FamilyInstance result = null;
			if (null != lineDir && arBeams != null)
			{
				double num = double.MaxValue;
				foreach (FamilyInstance familyInstance in arBeams)
				{
					int integerValue = familyInstance.Id.IntegerValue;
					Curve beamLocationCurveOnXYPlane = this.GetBeamLocationCurveOnXYPlane(familyInstance);
                    if (null != beamLocationCurveOnXYPlane && lineDir.Intersect(beamLocationCurveOnXYPlane) == (SetComparisonResult)8)
					{
						XYZ beamCenter = this.GetBeamCenter(familyInstance);
						if (beamCenter != null)
						{
							XYZ ptE = new XYZ(beamCenter.X, beamCenter.Y, 0.0);
							double num2 = this.PointOnCurveProjectLength(lineDir.Origin, ptE, lineDir);
							if (num2 < num)
							{
								num = num2;
								result = familyInstance;
							}
						}
					}
				}
			}
			return result;
		}

		private double GetRunBeamTolerance(StairsRun sRun)
		{
			double result = 1E-05;
			Stairs stairs = sRun.GetStairs();
			if (stairs != null)
			{
				Parameter parameter = stairs.GetParameter("实际踢面高度");
				if (parameter != null)
				{
					result = parameter.AsDouble();
				}
			}
			return result;
		}

		private FamilyInstance GetRunBeam(StairsRun sTopRun, StairsRun sBtmRun, bool bIsBottom = true)
		{
			FamilyInstance familyInstance = null;
			Stairs stairs = sTopRun.GetStairs();
			if (stairs == null)
			{
				return familyInstance;
			}
			bool flag = false;
			Dictionary<double, List<FamilyInstance>> dictionary;
			if (ElementXDataManager.StairsHasXDataGuid(stairs))
			{
				dictionary = this.GetStairsBeamInstance(sTopRun);
				if (dictionary.Count == 0)
				{
					flag = true;
				}
			}
			else
			{
				dictionary = this.GetDocumentAllBeams(this.m_doc);
			}
			if (flag)
			{
				dictionary = this.GetDocumentAllBeams(this.m_doc);
			}
			if (dictionary == null)
			{
				return familyInstance;
			}
			double stairsRunRefHeight = StairsRunParamManager.GetStairsRunRefHeight(sTopRun);
			StairsRunParamManager.GetActualRisersHeight(sTopRun);
			double num = sTopRun.BaseElevation + stairsRunRefHeight;
			if (!bIsBottom)
			{
				num = sTopRun.TopElevation + stairsRunRefHeight;
			}
			double runBeamTolerance = this.GetRunBeamTolerance(sTopRun);
			foreach (KeyValuePair<double, List<FamilyInstance>> keyValuePair in dictionary)
			{
				if (Math.Abs(keyValuePair.Key - num) < runBeamTolerance)
				{
					Line lineToOneSide = this.GetLineToOneSide(sBtmRun, bIsBottom);
					if (null != lineToOneSide)
					{
						familyInstance = this.GetMostNearToTreadBeam(lineToOneSide, keyValuePair.Value);
					}
					if (familyInstance == null)
					{
						Line oppositeLine = this.GetOppositeLine(lineToOneSide);
						if (null != oppositeLine)
						{
							familyInstance = this.GetMostNearToTreadBeam(oppositeLine, keyValuePair.Value);
						}
					}
					if (familyInstance != null)
					{
						break;
					}
				}
			}
			return familyInstance;
		}

		private FamilyInstance GetRunBeam(StairsRun sBtmRun, double dBeamHeight, bool bIsBottom = true)
		{
			FamilyInstance familyInstance = null;
			Dictionary<double, List<FamilyInstance>> documentAllBeams = this.GetDocumentAllBeams(this.m_doc);
			if (documentAllBeams == null)
			{
				return familyInstance;
			}
			double runBeamTolerance = this.GetRunBeamTolerance(sBtmRun);
			foreach (KeyValuePair<double, List<FamilyInstance>> keyValuePair in documentAllBeams)
			{
				if (Math.Abs(keyValuePair.Key - dBeamHeight) < runBeamTolerance)
				{
					Line lineToOneSide = this.GetLineToOneSide(sBtmRun, bIsBottom);
					if (null != lineToOneSide)
					{
						familyInstance = this.GetMostNearToTreadBeam(lineToOneSide, keyValuePair.Value);
					}
					if (familyInstance == null)
					{
						Line oppositeLine = this.GetOppositeLine(lineToOneSide);
						if (null != oppositeLine)
						{
							familyInstance = this.GetMostNearToTreadBeam(oppositeLine, keyValuePair.Value);
						}
					}
					if (familyInstance != null)
					{
						break;
					}
				}
			}
			return familyInstance;
		}

		private XYZ GetStairsRunRectCenter(StairsRun sRun)
		{
			XYZ result = null;
			if (sRun != null)
			{
				CurveLoop footprintBoundary = sRun.GetFootprintBoundary();
				CurveLoopSplit curveLoopSplit = new CurveLoopSplit(footprintBoundary);
				List<XYZ> curvesPoint = curveLoopSplit.GetCurvesPoint(CurveLoopSplit.CurveType.CT_LINE);
				if (curvesPoint.Count > 0)
				{
					XYZ xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(curvesPoint);
					if (xyz != null)
					{
						result = new XYZ(xyz.X, xyz.Y, 0.0);
					}
				}
			}
			return result;
		}

		private XYZ GetStairsRunTreadOutLineCenter(StairsRun sRun, bool bIsBottom = true)
		{
			XYZ result = null;
			XYZ stairsRunPath = this.GetStairsRunPath(sRun);
			XYZ stairsRunRectCenter = this.GetStairsRunRectCenter(sRun);
			double runProjectCycleLength = StairsRunParamManager.GetRunProjectCycleLength(sRun);
			XYZ xyz = stairsRunRectCenter - stairsRunPath.Multiply(runProjectCycleLength);
			if (!bIsBottom)
			{
				xyz = stairsRunRectCenter + stairsRunPath.Multiply(runProjectCycleLength);
			}
			Line curve = Line.CreateBound(stairsRunRectCenter, xyz);
			List<XYZ> curveToLoopIntersection = CurveLoopSplit.GetCurveToLoopIntersection(curve, sRun.GetFootprintBoundary());
			if (curveToLoopIntersection.Count > 0)
			{
				result = curveToLoopIntersection.First<XYZ>();
			}
			return result;
		}

		private Curve GetTransFormedCurve(Curve curve, XYZ vecTrans)
		{
			Curve curve2 = curve;
			if (null != curve2)
			{
				Transform transform = Transform.CreateTranslation(vecTrans);
				curve2 = curve.CreateTransformed(transform);
			}
			return curve2;
		}

		private Curve GetBeamLocationCurveOnXYPlane(FamilyInstance famBeam)
		{
			Curve result = null;
			if (famBeam != null)
			{
				LocationCurve locationCurve = famBeam.Location as LocationCurve;
				if (locationCurve != null)
				{
					BeamGeometryManager beamGeometryManager = new BeamGeometryManager(famBeam);
					Curve beamRealLocationCurve = beamGeometryManager.GetBeamRealLocationCurve();
					if (null != beamRealLocationCurve)
					{
						XYZ endPoint = beamRealLocationCurve.GetEndPoint(0);
						double num = -endPoint.Z;
						Transform transform = Transform.CreateTranslation(XYZ.BasisZ.Multiply(num));
						result = beamRealLocationCurve.CreateTransformed(transform);
					}
				}
			}
			return result;
		}

		private XYZ GetBeamCenter(FamilyInstance famBeam)
		{
			XYZ result = null;
			if (famBeam != null)
			{
				BeamGeometryManager beamGeometryManager = new BeamGeometryManager(famBeam);
				Curve beamRealLocationCurve = beamGeometryManager.GetBeamRealLocationCurve();
				if (null != beamRealLocationCurve)
				{
					XYZ endPoint = beamRealLocationCurve.GetEndPoint(0);
					XYZ endPoint2 = beamRealLocationCurve.GetEndPoint(1);
					result = YJKRGeometry.Geometry.CalculatMidPoint(endPoint, endPoint2);
				}
			}
			return result;
		}

		private double GetBeamHeight(FamilyInstance famBeam)
		{
			double result = 0.0;
			if (famBeam != null)
			{
				Parameter parameter = famBeam.Symbol.GetParameter("h");
				if (parameter != null)
				{
					result = parameter.AsDouble();
				}
			}
			return result;
		}

		private bool GetBeamBottomCenter(FamilyInstance famBeam, out XYZ ptBeamBtmCenter)
		{
			bool result = false;
			ptBeamBtmCenter = null;
			if (famBeam != null)
			{
				double beamHeight = this.GetBeamHeight(famBeam);
				XYZ beamCenter = this.GetBeamCenter(famBeam);
				if (beamCenter != null)
				{
					ptBeamBtmCenter = new XYZ(beamCenter.X, beamCenter.Y, beamCenter.Z - beamHeight);
					result = true;
				}
			}
			return result;
		}

		private double GetBeamWidth(FamilyInstance famBeam)
		{
			double result = 0.0;
			if (famBeam != null)
			{
				Parameter parameter = famBeam.Symbol.GetParameter("b");
				if (parameter != null)
				{
					result = parameter.AsDouble();
				}
			}
			return result;
		}

		private double GetDisBeamToRun(StairsRun sRun, FamilyInstance famBeam, bool bIsBottom = true)
		{
			double result = -1.0;
			if (sRun != null && famBeam != null)
			{
				XYZ stairsRunTreadOutLineCenter = this.GetStairsRunTreadOutLineCenter(sRun, bIsBottom);
				if (stairsRunTreadOutLineCenter != null)
				{
					LocationCurve locationCurve = famBeam.Location as LocationCurve;
					if (locationCurve != null)
					{
						XYZ beamCenter = this.GetBeamCenter(famBeam);
						XYZ ptE = new XYZ(beamCenter.X, beamCenter.Y, 0.0);
						double num = this.GetBeamWidth(famBeam) / 2.0;
						XYZ stairsRunPath = this.GetStairsRunPath(sRun);
						XYZ xyz = -stairsRunPath;
						if (!bIsBottom)
						{
							xyz = stairsRunPath;
						}
						Line curve = Line.CreateUnbound(stairsRunTreadOutLineCenter, xyz);
						double num2 = this.PointOnCurveProjectLength(stairsRunTreadOutLineCenter, ptE, curve);
						result = num2 - num;
					}
				}
			}
			return result;
		}

		private double CalcRunCHeightLessThan300MM(StairsRun sBtmRun, StairsRun sTopRun, FamilyInstance famBeam, bool bIsBottom = true)
		{
			double result = -1.0;
			if (sBtmRun != null && sTopRun != null && famBeam != null)
			{
				XYZ beamCenter = this.GetBeamCenter(famBeam);
				double beamHeight = this.GetBeamHeight(famBeam);
				double num = beamCenter.Z - beamHeight;
				double actualRisersHeight = StairsRunParamManager.GetActualRisersHeight(sBtmRun);
				StairsRunParamManager.GetTreadThickness(sBtmRun);
				double num2;
				if (bIsBottom)
				{
					double absoluteBaseElevation = StairsRunParamManager.GetAbsoluteBaseElevation(sBtmRun);
					num2 = absoluteBaseElevation + actualRisersHeight;
				}
				else
				{
					double absoluteTopElevation = StairsRunParamManager.GetAbsoluteTopElevation(sBtmRun);
					double num3 = actualRisersHeight;
					double dTol = YJKArchMethodLibrary.Utils.Common.MMToFeet(150.0);
					bool flag = this.IsRunConnectLand(sBtmRun, sTopRun, dTol, bIsBottom);
					if (flag)
					{
						num2 = absoluteTopElevation + num3;
					}
					else
					{
						num2 = absoluteTopElevation - num3;
					}
				}
				result = num - num2;
			}
			return result;
		}

		private List<CurveLoop> CreateBeamCurveLoop(FamilyInstance famBeam, XYZ vecUpStairs)
		{
			List<CurveLoop> list = new List<CurveLoop>();
			if (famBeam != null)
			{
				BeamGeometryManager beamGeometryManager = new BeamGeometryManager(famBeam);
				Curve beamRealLocationCurve = beamGeometryManager.GetBeamRealLocationCurve();
				if (null != beamRealLocationCurve)
				{
					double num = this.GetBeamHeight(famBeam) + YJKArchMethodLibrary.Utils.Common.MMToFeet(100.0);
					XYZ vecTrans = -XYZ.BasisZ.Multiply(num);
					Curve transFormedCurve = this.GetTransFormedCurve(beamRealLocationCurve, vecTrans);
					XYZ endPoint = transFormedCurve.GetEndPoint(0);
					XYZ endPoint2 = transFormedCurve.GetEndPoint(1);
					XYZ xyz = vecUpStairs.Normalize();
					double beamWidth = this.GetBeamWidth(famBeam);
					double num2 = beamWidth / 2.0;
					XYZ xyz2 = -xyz.Multiply(num2);
					XYZ xyz3 = xyz.Multiply(beamWidth);
					XYZ xyz4 = endPoint - xyz2;
					XYZ xyz5 = endPoint2 - xyz2;
					XYZ xyz6 = xyz4 + xyz3;
					XYZ xyz7 = xyz5 + xyz3;
					List<Curve> list2 = new List<Curve>();
					list2.Add(Line.CreateBound(xyz4, xyz6));
					list2.Add(Line.CreateBound(xyz6, xyz7));
					list2.Add(Line.CreateBound(xyz7, xyz5));
					list2.Add(Line.CreateBound(xyz5, xyz4));
					if (list2.Count > 2)
					{
						list.Add(CurveLoop.Create(list2));
					}
				}
			}
			return list;
		}

		private double CalcRunCHeightGreaterThan300MM(StairsRun sBtmRun, FamilyInstance famBeam, bool bIsBottom = true)
		{
			double result = -1.0;
			if (famBeam != null)
			{
				XYZ beamCenter = this.GetBeamCenter(famBeam);
				StairsRunParamManager.GetStairsRunRefHeight(sBtmRun);
				if (beamCenter != null)
				{
					XYZ stairsRunPath = this.GetStairsRunPath(sBtmRun);
					List<CurveLoop> list = this.CreateBeamCurveLoop(famBeam, stairsRunPath);
					if (list.Count > 0)
					{
						double dExtenalDist = YJKArchMethodLibrary.Utils.Common.MMToFeet(10000.0);
						XYZ solidFloorNearUpPoint = this.m_floorSearch.GetSolidFloorNearUpPoint(beamCenter, list, dExtenalDist, -XYZ.BasisZ);
						XYZ solidLandingNearUpPoint = this.m_floorSearch.GetSolidLandingNearUpPoint(beamCenter, list, dExtenalDist, -XYZ.BasisZ);
						if (solidLandingNearUpPoint != null && solidFloorNearUpPoint == null)
						{
							double beamHeight = this.GetBeamHeight(famBeam);
							XYZ xyz = solidLandingNearUpPoint;
							result = beamCenter.Z - xyz.Z - beamHeight;
						}
						else if (solidLandingNearUpPoint == null && solidFloorNearUpPoint != null)
						{
							double beamHeight2 = this.GetBeamHeight(famBeam);
							XYZ xyz2 = solidFloorNearUpPoint;
							result = beamCenter.Z - xyz2.Z - beamHeight2;
						}
						else if (solidLandingNearUpPoint != null && solidFloorNearUpPoint != null)
						{
							double beamHeight3 = this.GetBeamHeight(famBeam);
							XYZ xyz3 = solidFloorNearUpPoint;
							if (solidLandingNearUpPoint.Z > solidFloorNearUpPoint.Z)
							{
								xyz3 = solidLandingNearUpPoint;
							}
							result = beamCenter.Z - xyz3.Z - beamHeight3;
						}
					}
				}
			}
			return result;
		}

		private bool CheckStairsRun300MMClearHeight(StairsRun sBtmRun, StairsRun sTopRun, double dStdValue, bool bIsBottom = true)
		{
			bool result = false;
			if (sBtmRun != null && sTopRun != null)
			{
				YJKArchMethodLibrary.Utils.Common.MMToFeet(150.0);
				FamilyInstance runBeam = this.GetRunBeam(sTopRun, sBtmRun, bIsBottom);
				if (runBeam != null)
				{
					double disBeamToRun = this.GetDisBeamToRun(sBtmRun, runBeam, bIsBottom);
					if (disBeamToRun > -1.0)
					{
						double d300Cmp = this.m_d300Cmp;
						double num;
						if (disBeamToRun < d300Cmp)
						{
							num = this.CalcRunCHeightLessThan300MM(sBtmRun, sTopRun, runBeam, bIsBottom);
						}
						else
						{
							num = this.CalcRunCHeightGreaterThan300MM(sBtmRun, runBeam, bIsBottom);
						}
						if (num > -1.0 && num < dStdValue)
						{
							result = true;
						}
					}
				}
			}
			return result;
		}

		private double PointOnCurveProjectLength(XYZ ptS, XYZ ptE, Curve curve)
		{
			double result = 0.0;
			if (ptE != null && ptS != null && null != curve)
			{
				IntersectionResult intersectionResult = curve.Project(ptE);
                if (intersectionResult != null)
				{
					double distance = intersectionResult.Distance;
					double num = ptS.DistanceTo(ptE);
					result = Math.Sqrt(num * num - distance * distance);
				}
			}
			return result;
		}

		private List<XYZ> GetPointsGreaterThan300MM(StairsRun sBtmRun, StairsRun sTopRun, FamilyInstance famBeam, XYZ ptRunInter, bool bIsBottom = true)
		{
			List<XYZ> list = new List<XYZ>();
			if (sBtmRun != null && sTopRun != null && famBeam != null)
			{
				XYZ beamCenter = this.GetBeamCenter(famBeam);
				double beamHeight = this.GetBeamHeight(famBeam);
				XYZ xyz = null;
				if (beamCenter != null)
				{
					xyz = new XYZ(ptRunInter.X, ptRunInter.Y, beamCenter.Z - beamHeight);
				}
				if (xyz != null)
				{
					XYZ xyz2 = -this.GetStairsRunPath(sTopRun);
					if (!bIsBottom)
					{
						xyz2 = -xyz2;
					}
					double num = 0.0;
					XYZ xyz3 = new XYZ(xyz.X, xyz.Y, 0.0);
					Line line = Line.CreateUnbound(xyz3, xyz2);
					XYZ xyz4 = new XYZ(beamCenter.X, beamCenter.Y, 0.0);
					if (null != line && xyz4 != null)
					{
						num = this.PointOnCurveProjectLength(xyz3, xyz4, line);
					}
					XYZ xyz5 = xyz2.Multiply(num);
					xyz += xyz5;
					Line.CreateUnbound(xyz, XYZ.BasisZ);
					YJKArchMethodLibrary.Utils.Common.MMToFeet(150.0);
					StairsRunParamManager.GetAbsoluteBaseElevation(sBtmRun);
					if (!bIsBottom)
					{
						StairsRunParamManager.GetAbsoluteTopElevation(sBtmRun);
					}
					double num2 = this.CalcRunCHeightGreaterThan300MM(sBtmRun, famBeam, bIsBottom);
					if (num2 > 0.0)
					{
						XYZ xyz6 = -XYZ.BasisZ.Multiply(num2);
						XYZ item = xyz + xyz6;
						list.Add(xyz);
						list.Add(item);
					}
				}
			}
			return list;
		}

		private List<XYZ> GetPointsLessThan300MM(StairsRun sBtmRun, StairsRun sTopRun, FamilyInstance famBeam, XYZ ptRunInter, bool bIsBottom = true)
		{
			List<XYZ> list = new List<XYZ>();
			if (sBtmRun != null && sTopRun != null && famBeam != null)
			{
				XYZ beamCenter = this.GetBeamCenter(famBeam);
				XYZ xyz = null;
				if (beamCenter != null)
				{
					double beamHeight = this.GetBeamHeight(famBeam);
					xyz = new XYZ(ptRunInter.X, ptRunInter.Y, beamCenter.Z - beamHeight);
				}
				if (xyz != null)
				{
					double num = this.CalcRunCHeightLessThan300MM(sBtmRun, sTopRun, famBeam, bIsBottom);
					if (num > -1.0)
					{
						XYZ xyz2 = -XYZ.BasisZ.Multiply(num);
						XYZ xyz3 = xyz + xyz2;
						XYZ xyz4 = -this.GetStairsRunPath(sTopRun);
						if (!bIsBottom)
						{
							xyz4 = -xyz4;
						}
						double num2 = 0.0;
						XYZ xyz5 = new XYZ(xyz.X, xyz.Y, 0.0);
						Line line = Line.CreateUnbound(xyz5, xyz4);
						XYZ xyz6 = new XYZ(beamCenter.X, beamCenter.Y, 0.0);
						if (null != line && xyz6 != null)
						{
							num2 = this.PointOnCurveProjectLength(xyz5, xyz6, line);
						}
						XYZ xyz7 = xyz4.Multiply(num2);
						list.Add(xyz + xyz7);
						list.Add(xyz3 + xyz7);
					}
				}
			}
			return list;
		}

		private void Draw300MMDimension(StairsRun sBtmRun, StairsRun sTopRun, XYZ ptRunInter, ElementId dimTypeId, ref List<DimesionDataManager> lstDimData, bool bIsBottom = true)
		{
			if (sBtmRun == null || sTopRun == null)
			{
				return;
			}
			FamilyInstance runBeam = this.GetRunBeam(sTopRun, sBtmRun, bIsBottom);
			if (runBeam == null)
			{
				return;
			}
			double disBeamToRun = this.GetDisBeamToRun(sBtmRun, runBeam, bIsBottom);
			if (disBeamToRun < 0.0)
			{
				return;
			}
			List<XYZ> list = null;
			if (disBeamToRun < this.m_d300Cmp)
			{
				list = this.GetPointsLessThan300MM(sBtmRun, sTopRun, runBeam, ptRunInter, bIsBottom);
			}
			else
			{
				double dTol = YJKArchMethodLibrary.Utils.Common.MMToFeet(150.0);
				if (!this.IsRunConnectLand(sBtmRun, sTopRun, dTol, bIsBottom))
				{
					list = this.GetPointsGreaterThan300MM(sBtmRun, sTopRun, runBeam, ptRunInter, bIsBottom);
				}
			}
			if (list == null || 2 != list.Count)
			{
				return;
			}
			XYZ xyz = this.GetStairsRunPath(sBtmRun);
			if (xyz == null)
			{
				return;
			}
			if (!bIsBottom)
			{
				xyz = -xyz;
			}
			DimesionDataManager item = new DimesionDataManager(this.m_viewId, list[0], list[1], dimTypeId, xyz);
			lstDimData.Add(item);
		}

		private StairsRun GetStairsLandCutRun(ElementId idLand, ref bool bBottom)
		{
			StairsRun result = null;
			StairsLanding stairsLanding = this.m_doc.GetElement(idLand) as StairsLanding;
			if (stairsLanding == null)
			{
				return result;
			}
			List<List<StairsClearHeightMgr.ClearHeightData>> list = this.m_dimensionData[StairsClearHeightMgr.DimObjType.DOT_RUN];
			if (list.Count < 1)
			{
				return result;
			}
			ElementId insectionId = list.First<List<StairsClearHeightMgr.ClearHeightData>>().First<StairsClearHeightMgr.ClearHeightData>().m_Intersection.First<StairsClearHeightMgr.IntersectionData>().m_InsectionId;
			StairsRun stairsRun = this.m_doc.GetElement(insectionId) as StairsRun;
			if (stairsRun == null)
			{
				return result;
			}
			XYZ stairsRunPath = this.GetStairsRunPath(stairsRun);
			IList<StairsComponentConnection> connections = stairsLanding.GetConnections();
			foreach (StairsComponentConnection stairsComponentConnection in connections)
			{
				StairsRun stairsRun2 = this.m_doc.GetElement(stairsComponentConnection.PeerElementId) as StairsRun;
				if (stairsRun2 != null)
				{
					XYZ stairsRunPath2 = this.GetStairsRunPath(stairsRun2);
					if (YJKArchMethodLibrary.Utils.Geometry.IsParallel(stairsRunPath, stairsRunPath2, 1E-09))
					{
						result = stairsRun2;
                        if ((int)stairsComponentConnection.PeerConnectionType == 1)
						{
							bBottom = true;
							break;
						}
						bBottom = false;
						break;
					}
				}
			}
			return result;
		}

		public bool InitData(StairsClearHeightMgr.InitDataType initType, List<ElementId> ListStairIds)
		{
			bool result = true;
			this.InitCheckClearHeightData(ListStairIds);
			return result;
		}

		public bool InitData(StairsClearHeightMgr.InitDataType initType)
		{
			bool result = true;
			this.m_initDataType = initType;
			List<Element> arStairs = new List<Element>();
			if (this.m_viewId == null)
			{
				ElementClassFilter filter = new ElementClassFilter(typeof(Stairs));
				arStairs = FloorSearchManager.FilterElemByKind(filter, this.m_doc);
			}
			else
			{
				arStairs = this.GetOneViewAllStairs();
			}
			List<ElementId> stairsIds = this.GetStairsIds(arStairs);
			switch (this.m_initDataType)
			{
			case StairsClearHeightMgr.InitDataType.INIT_CHKCLEARHEIGHT:
				this.InitCheckClearHeightData(stairsIds);
				break;
			case StairsClearHeightMgr.InitDataType.INIT_DMSCLEARHEIGHT:
				this.InitDimensionClearHeightData(stairsIds);
				break;
			}
			return result;
		}

		public bool CheckStairsClearHeight(StairsClearHeightMgr.CheckType chkType, ElementId stairsId, out string sTip)
		{
			bool flag = false;
			sTip = null;
			double num = YJKArchMethodLibrary.Utils.Common.MMToFeet(2200.0);
			double num2 = YJKArchMethodLibrary.Utils.Common.MMToFeet(2000.0);
			double dStdValue = num;
			double dBeamDepth = 0.0;
			string text = "梯段净高值不满足《民用建筑设计通则》梯段净高不宜小于2.2m";
			this.m_doc.GetElement(stairsId);
			if (chkType == StairsClearHeightMgr.CheckType.CT_SLAND)
			{
				dStdValue = num2;
				text = "楼梯平台净高值不满足《民用建筑设计通则》楼梯平台上部及下部过道处的净高不应小于2m";
			}
			List<List<StairsClearHeightMgr.ClearHeightData>> list = this.m_checkData[chkType];
			foreach (List<StairsClearHeightMgr.ClearHeightData> list2 in list)
			{
				if (list2.Count != 1)
				{
					for (int i = 0; i < list2.Count - 1; i++)
					{
						if (list2[i].m_StairsId.Equals(stairsId))
						{
							if (chkType == StairsClearHeightMgr.CheckType.CT_SLAND)
							{
								StairsClearHeightMgr.IntersectionData intersectionData = list2[i + 1].m_Intersection.First<StairsClearHeightMgr.IntersectionData>();
								if (intersectionData != null)
								{
									dBeamDepth = this.GetStairsBeamDepth(intersectionData.m_InsectionId);
								}
							}
							flag = this.CompareTwoCHData(chkType, list2[i], list2[i + 1], dStdValue, dBeamDepth);
						}
						if (flag)
						{
							sTip = text;
							break;
						}
					}
				}
			}
			return flag;
		}

		private bool CompareTwoCHData(StairsClearHeightMgr.CheckType chkType, StairsClearHeightMgr.ClearHeightData srcCHData, StairsClearHeightMgr.ClearHeightData destCHData, double dStdValue, double dBeamDepth)
		{
			bool result = false;
			foreach (StairsClearHeightMgr.IntersectionData intersectionData in srcCHData.m_Intersection)
			{
				bool flag = false;
				double z = intersectionData.m_MaxMinPoint.m_ptMax.Z;
				foreach (StairsClearHeightMgr.IntersectionData intersectionData2 in destCHData.m_Intersection)
				{
					if (intersectionData.m_nGroupNum == intersectionData2.m_nGroupNum)
					{
						double z2 = intersectionData2.m_MaxMinPoint.m_ptMin.Z;
						double num = z2 - z - dBeamDepth;
						if (num < dStdValue)
						{
							flag = true;
							result = true;
							break;
						}
						if (chkType == StairsClearHeightMgr.CheckType.CT_SRUN)
						{
							double dStdValue2 = YJKArchMethodLibrary.Utils.Common.MMToFeet(2000.0);
							StairsRun sBtmRun = this.m_doc.GetElement(intersectionData.m_InsectionId) as StairsRun;
							StairsRun sTopRun = this.m_doc.GetElement(intersectionData2.m_InsectionId) as StairsRun;
							flag = this.CheckStairsRun300MMClearHeight(sBtmRun, sTopRun, dStdValue2, true);
							if (!flag)
							{
								flag = this.CheckStairsRun300MMClearHeight(sBtmRun, sTopRun, dStdValue2, false);
							}
							if (flag)
							{
								result = true;
								break;
							}
						}
					}
				}
				if (flag)
				{
					break;
				}
			}
			return result;
		}

		public void DrawStairsDimesion(StairsClearHeightMgr.DimObjType dimObjType, ref List<DimesionDataManager> lstDimData, ElementId dimTypeId = null)
		{
			List<List<StairsClearHeightMgr.ClearHeightData>> list = null;
			switch (dimObjType)
			{
			case StairsClearHeightMgr.DimObjType.DOT_RUN:
				list = this.m_dimensionData[dimObjType];
				break;
			case StairsClearHeightMgr.DimObjType.DOT_LAND:
				list = this.m_dimensionData[dimObjType];
				break;
			}
			if (list != null)
			{
				foreach (List<StairsClearHeightMgr.ClearHeightData> list2 in list)
				{
					if (list2.Count != 1)
					{
						for (int i = 0; i < list2.Count - 1; i++)
						{
							ElementId stairsId = list2[i].m_StairsId;
							if (this.IsMoreLevelStairs(stairsId))
							{
								Stairs stairs = this.m_doc.GetElement(stairsId) as Stairs;
								if (stairs != null)
								{
									StairsClearHeightMgr.ClearHeightData btmCHData = list2[i];
									StairsClearHeightMgr.ClearHeightData topCHData = list2[i + 1];
									this.CreateMoreLevelDimesion(lstDimData, dimTypeId, stairs, btmCHData, topCHData);
								}
							}
							else
							{
								this.CreateAllDimension(dimObjType, list2[i], list2[i + 1], ref lstDimData, dimTypeId);
							}
						}
					}
				}
			}
		}

		private void CreateMoreLevelDimesion(List<DimesionDataManager> lstDimData, ElementId dimTypeId, Stairs baseStairs, StairsClearHeightMgr.ClearHeightData btmCHData, StairsClearHeightMgr.ClearHeightData topCHData)
		{
			foreach (StairsClearHeightMgr.IntersectionData intersectionData in btmCHData.m_Intersection)
			{
				XYZ vecDirection = null;
				StairsRun stairsRun = null;
				StairsLanding stairsLanding = null;
				Element element = this.m_doc.GetElement(intersectionData.m_InsectionId);
				if (element != null)
				{
					if (element.GetType() == typeof(StairsRun))
					{
						stairsRun = (element as StairsRun);
						if (stairsRun != null)
						{
							vecDirection = this.GetStairsRunPath(stairsRun);
						}
					}
					else if (element.GetType() == typeof(StairsLanding))
					{
						stairsLanding = (element as StairsLanding);
						if (stairsLanding != null)
						{
							vecDirection = this.GetStairsLandDirection(stairsLanding, intersectionData.m_MaxMinPoint.m_ptMax);
						}
					}
					XYZ ptMax = intersectionData.m_MaxMinPoint.m_ptMax;
					double dOffsetZ = intersectionData.m_MaxMinPoint.m_ptMax.DistanceTo(intersectionData.m_MaxMinPoint.m_ptMin);
					double height = baseStairs.Height;
					int moreLevelStairsLevels = StairsMoreLevelManager.GetMoreLevelStairsLevels(baseStairs);
					this.CreateMoreLevelInDimesion(ref lstDimData, dimTypeId, vecDirection, stairsRun, stairsLanding, ref ptMax, dOffsetZ, height, moreLevelStairsLevels);
					this.CreateMoreLeveLastStairsDimesion(lstDimData, dimTypeId, topCHData, intersectionData, vecDirection, stairsRun, ptMax, height, moreLevelStairsLevels);
				}
			}
		}

		private void CreateMoreLeveLastStairsDimesion(List<DimesionDataManager> lstDimData, ElementId dimTypeId, StairsClearHeightMgr.ClearHeightData topCHData, StairsClearHeightMgr.IntersectionData btmInterData, XYZ vecDirection, StairsRun BaseRun, XYZ ptBtm, double dStairsHeight, int nTransDim)
		{
			foreach (StairsClearHeightMgr.IntersectionData intersectionData in topCHData.m_Intersection)
			{
				if (btmInterData.m_nGroupNum == intersectionData.m_nGroupNum)
				{
					Element element = this.m_doc.GetElement(intersectionData.m_InsectionId);
					if (element is StairsRun)
					{
						StairsRun stairsRun = element as StairsRun;
						if (stairsRun != null)
						{
							XYZ ptMin = intersectionData.m_MaxMinPoint.m_ptMin;
							DimesionDataManager item = new DimesionDataManager(this.m_viewId, ptBtm, ptMin, dimTypeId, vecDirection);
							lstDimData.Add(item);
							bool bIsBottom = false;
							this.DrawMoreLevelLastRun300MMDimesion(lstDimData, dimTypeId, vecDirection, BaseRun, ptBtm, dStairsHeight, nTransDim, stairsRun, bIsBottom);
							bIsBottom = true;
							this.DrawMoreLevelLastRun300MMDimesion(lstDimData, dimTypeId, vecDirection, BaseRun, ptBtm, dStairsHeight, nTransDim, stairsRun, bIsBottom);
						}
					}
					else if (element is StairsLanding)
					{
						StairsLanding stairsLanding = element as StairsLanding;
						if (stairsLanding != null)
						{
							FamilyInstance famBeam = null;
							XYZ xyz = null;
							this.GetDimLandBeamsDepth(stairsLanding.Id, out xyz, out famBeam);
							if (xyz != null)
							{
								bool bIsBottom2 = false;
								StairsRun stairsLandCutRun = this.GetStairsLandCutRun(btmInterData.m_InsectionId, ref bIsBottom2);
								if (stairsLandCutRun != null)
								{
									double disBeamToRun = this.GetDisBeamToRun(stairsLandCutRun, famBeam, bIsBottom2);
									if (disBeamToRun > this.m_d300Cmp)
									{
										XYZ ptEnd = xyz;
										XYZ ptStart = new XYZ(xyz.X, xyz.Y, ptBtm.Z);
										DimesionDataManager item2 = new DimesionDataManager(this.m_viewId, ptStart, ptEnd, dimTypeId, vecDirection);
										lstDimData.Add(item2);
									}
								}
							}
						}
					}
				}
			}
		}

		private void CreateMoreLevelInDimesion(ref List<DimesionDataManager> lstDimData, ElementId dimTypeId, XYZ vecDirection, StairsRun BaseRun, StairsLanding BaseLand, ref XYZ ptBtm, double dOffsetZ, double dStairsHeight, int nTransDim)
		{
			for (int i = 1; i < nTransDim; i++)
			{
				double num = ptBtm.Z + dStairsHeight;
				XYZ ptEnd = new XYZ(ptBtm.X, ptBtm.Y, num - dOffsetZ);
				if (BaseRun != null)
				{
					DimesionDataManager item = new DimesionDataManager(this.m_viewId, ptBtm, ptEnd, dimTypeId, vecDirection);
					lstDimData.Add(item);
					double dTopBeamHeight = StairsRunParamManager.GetAbsoluteTopElevation(BaseRun) + (double)i * dStairsHeight;
					bool bIsBottom = false;
					this.DrawMoreLevelRun300MMDimesion(BaseRun, dimTypeId, vecDirection, ptBtm, dStairsHeight, dTopBeamHeight, ref lstDimData, bIsBottom);
					double dTopBeamHeight2 = StairsRunParamManager.GetAbsoluteBaseElevation(BaseRun) + (double)i * dStairsHeight;
					bIsBottom = true;
					this.DrawMoreLevelRun300MMDimesion(BaseRun, dimTypeId, vecDirection, ptBtm, dStairsHeight, dTopBeamHeight2, ref lstDimData, bIsBottom);
				}
				if (BaseLand != null)
				{
					double num2 = StairsLandingParamManager.GetAbsoluteElevation(BaseLand) + (double)i * dStairsHeight;
					FamilyInstance moreLevelLandBeam = this.GetMoreLevelLandBeam(BaseLand, num2, num2, dStairsHeight, -XYZ.BasisZ);
					if (moreLevelLandBeam != null)
					{
						bool bIsBottom2 = false;
						StairsRun stairsLandCutRun = this.GetStairsLandCutRun(BaseLand.Id, ref bIsBottom2);
						if (stairsLandCutRun != null)
						{
							double disBeamToRun = this.GetDisBeamToRun(stairsLandCutRun, moreLevelLandBeam, bIsBottom2);
							if (disBeamToRun > this.m_d300Cmp)
							{
								XYZ xyz = null;
								bool beamBottomCenter = this.GetBeamBottomCenter(moreLevelLandBeam, out xyz);
								XYZ xyz2 = null;
								if (beamBottomCenter)
								{
									xyz2 = new XYZ(xyz.X, xyz.Y, ptBtm.Z);
								}
								if (xyz != null && xyz2 != null)
								{
									DimesionDataManager item2 = new DimesionDataManager(this.m_viewId, xyz2, xyz, dimTypeId, vecDirection);
									lstDimData.Add(item2);
								}
							}
						}
					}
					else
					{
						DimesionDataManager item3 = new DimesionDataManager(this.m_viewId, ptBtm, ptEnd, dimTypeId, vecDirection);
						lstDimData.Add(item3);
					}
				}
				ptBtm = new XYZ(ptBtm.X, ptBtm.Y, num);
			}
		}

		private void DrawMoreLevelLastRun300MMDimesion(List<DimesionDataManager> lstDimData, ElementId dimTypeId, XYZ vecDirection, StairsRun BaseRun, XYZ ptBtm, double dStairsHeight, int nTransDim, StairsRun topRun, bool bIsBottom)
		{
			FamilyInstance runBeam = this.GetRunBeam(topRun, BaseRun, bIsBottom);
			if (runBeam != null)
			{
				double disBeamToRun = this.GetDisBeamToRun(BaseRun, runBeam, bIsBottom);
				if (disBeamToRun > -1.0)
				{
					XYZ xyz = null;
					XYZ xyz2 = null;
					if (disBeamToRun < this.m_d300Cmp)
					{
						if (this.GetBeamBottomCenter(runBeam, out xyz))
						{
							double actualRisersHeight = StairsRunParamManager.GetActualRisersHeight(BaseRun);
							if (bIsBottom)
							{
								double absoluteBaseElevation = StairsRunParamManager.GetAbsoluteBaseElevation(BaseRun);
								double num = absoluteBaseElevation + (double)(nTransDim - 1) * dStairsHeight + actualRisersHeight;
								xyz2 = new XYZ(xyz.X, xyz.Y, num);
							}
							else
							{
								double absoluteTopElevation = StairsRunParamManager.GetAbsoluteTopElevation(BaseRun);
								double num2 = absoluteTopElevation + (double)(nTransDim - 1) * dStairsHeight + actualRisersHeight;
								xyz2 = new XYZ(xyz.X, xyz.Y, num2);
							}
						}
					}
					else if (!this.IsRunConnectLand(BaseRun, topRun, this.m_dTol, bIsBottom))
					{
						List<XYZ> pointsGreaterThan300MM = this.GetPointsGreaterThan300MM(BaseRun, BaseRun, runBeam, ptBtm, bIsBottom);
						if (2 == pointsGreaterThan300MM.Count)
						{
							xyz = pointsGreaterThan300MM.First<XYZ>();
							xyz2 = pointsGreaterThan300MM.Last<XYZ>();
						}
					}
					if (xyz2 != null && xyz != null)
					{
						if (!bIsBottom)
						{
							vecDirection = -vecDirection;
						}
						DimesionDataManager item = new DimesionDataManager(this.m_viewId, xyz2, xyz, dimTypeId, vecDirection);
						lstDimData.Add(item);
					}
				}
			}
		}

		private void DrawMoreLevelRun300MMDimesion(StairsRun BaseRun, ElementId dimTypeId, XYZ vecDirection, XYZ ptBtm, double dStairsHeight, double dTopBeamHeight, ref List<DimesionDataManager> lstDimData, bool bIsBottom = true)
		{
			FamilyInstance runBeam = this.GetRunBeam(BaseRun, dTopBeamHeight, bIsBottom);
			if (runBeam != null)
			{
				double disBeamToRun = this.GetDisBeamToRun(BaseRun, runBeam, bIsBottom);
				bool flag = this.IsRunConnectLand(BaseRun, BaseRun, this.m_dTol, bIsBottom);
				XYZ xyz = null;
				XYZ xyz2 = null;
				if (disBeamToRun > this.m_d300Cmp)
				{
					if (!flag)
					{
						List<XYZ> pointsGreaterThan300MM = this.GetPointsGreaterThan300MM(BaseRun, BaseRun, runBeam, ptBtm, bIsBottom);
						if (2 == pointsGreaterThan300MM.Count)
						{
							xyz = pointsGreaterThan300MM.First<XYZ>();
							xyz2 = pointsGreaterThan300MM.Last<XYZ>();
						}
					}
				}
				else
				{
					XYZ beamCenter = this.GetBeamCenter(runBeam);
					if (beamCenter != null)
					{
						double beamHeight = this.GetBeamHeight(runBeam);
						xyz = new XYZ(ptBtm.X, ptBtm.Y, beamCenter.Z - beamHeight);
					}
					if (xyz != null)
					{
						double num = dTopBeamHeight - dStairsHeight + StairsRunParamManager.GetActualRisersHeight(BaseRun);
						xyz2 = new XYZ(xyz.X, xyz.Y, num);
						XYZ xyz3 = -this.GetStairsRunPath(BaseRun);
						if (!bIsBottom)
						{
							xyz3 = -xyz3;
						}
						double num2 = 0.0;
						XYZ xyz4 = new XYZ(xyz.X, xyz.Y, 0.0);
						Line line = Line.CreateUnbound(xyz4, xyz3);
						XYZ xyz5 = new XYZ(beamCenter.X, beamCenter.Y, 0.0);
						if (null != line && xyz5 != null)
						{
							num2 = this.PointOnCurveProjectLength(xyz4, xyz5, line);
						}
						XYZ xyz6 = xyz3.Multiply(num2);
						xyz += xyz6;
						xyz2 += xyz6;
					}
				}
				if (xyz != null && xyz2 != null)
				{
					XYZ xyz7 = vecDirection;
					if (!bIsBottom)
					{
						xyz7 = -xyz7;
					}
					DimesionDataManager item = new DimesionDataManager(this.m_viewId, xyz2, xyz, dimTypeId, xyz7);
					lstDimData.Add(item);
				}
			}
		}

		private Dimension CreateOneDimension(XYZ ptS, XYZ ptE, ElementId dimTypeId = null, XYZ vecLineDir = null)
		{
			int num = this.m_doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger();
			DimensionType dimensionType = null;
			double num2 = 0.0;
			if (null != dimTypeId)
			{
				dimensionType = (this.m_doc.GetElement(dimTypeId) as DimensionType);
				if (dimensionType != null)
				{
					Parameter parameter = dimensionType.GetParameter("尺寸界线长度");
					if (parameter != null)
					{
						num2 = YJKArchMethodLibrary.Utils.Common.FeetToMM(parameter.AsDouble());
					}
				}
			}
			double num3 = YJKArchMethodLibrary.Utils.Common.MMToFeet(num2 * (double)num);
			double num4 = YJKArchMethodLibrary.Utils.Common.MMToFeet(1.0);
			ViewSection viewSection = this.m_doc.GetElement(this.m_viewId) as ViewSection;
			if (viewSection == null)
			{
				return null;
			}
			XYZ xyz = viewSection.RightDirection;
			if (vecLineDir != null)
			{
				xyz = vecLineDir;
			}
			xyz = xyz.Normalize();
			XYZ xyz2 = -xyz.Multiply(num3);
			XYZ xyz3 = ptS + xyz.Multiply(num4);
			XYZ xyz4 = ptE + xyz.Multiply(num4);
			Line line = Line.CreateBound(ptS, xyz3);
			Line line2 = Line.CreateBound(ptE, xyz4);
			Line line3 = Line.CreateBound(ptS + xyz2, ptE + xyz2);
			ReferenceArray referenceArray = new ReferenceArray();
			List<ElementId> list = new List<ElementId>();
			DetailLine detailLine = this.m_doc.Create.NewDetailCurve(viewSection, line) as DetailLine;
			DetailLine detailLine2 = this.m_doc.Create.NewDetailCurve(viewSection, line2) as DetailLine;
			Reference reference = detailLine.GeometryCurve.Reference;
			Reference reference2 = detailLine2.GeometryCurve.Reference;
			referenceArray.Append(reference);
			referenceArray.Append(reference2);
			list.Add(detailLine.Id);
			list.Add(detailLine2.Id);
			Dimension dimension;
			if (dimensionType != null)
			{
				dimension = this.m_doc.Create.NewDimension(viewSection, line3, referenceArray, dimensionType);
			}
			else
			{
				dimension = this.m_doc.Create.NewDimension(viewSection, line3, referenceArray);
			}
			StairsDimXDataMgr.WriteDimensionXData(dimension, list);
			return dimension;
		}

		private XYZ GetStairsRunPath(StairsRun sRun)
		{
			XYZ xyz = null;
			if (sRun != null)
			{
				CurveLoop stairsPath = sRun.GetStairsPath();
				if (stairsPath != null)
				{
					CurveLoopSplit curveLoopSplit = new CurveLoopSplit(stairsPath);
					List<XYZ> curvesPoint = curveLoopSplit.GetCurvesPoint(CurveLoopSplit.CurveType.CT_LINE);
					if (curvesPoint.Count > 1)
					{
						xyz = curvesPoint[1] - curvesPoint[0];
						xyz = xyz.Normalize();
					}
				}
			}
			return xyz;
		}

		private XYZ GetStairsLandDirection(StairsLanding sLand, XYZ ptLand)
		{
			XYZ result = null;
			ViewSection viewSection = this.m_doc.GetElement(this.m_viewId) as ViewSection;
			if (sLand != null && viewSection != null)
			{
				Stairs stairs = sLand.GetStairs();
				Line line = this.ViewSectionToCutLine(viewSection);
				if (stairs != null && null != line)
				{
					XYZ xyz = null;
					foreach (ElementId elementId in stairs.GetStairsRuns())
					{
						StairsRun stairsRun = this.m_doc.GetElement(elementId) as StairsRun;
						if (stairsRun != null)
						{
							CurveLoop footprintBoundary = stairsRun.GetFootprintBoundary();
							List<XYZ> curveToLoopIntersection = CurveLoopSplit.GetCurveToLoopIntersection(line, footprintBoundary);
							if (curveToLoopIntersection.Count > 0)
							{
								xyz = StairsClearHeightDimensionGeometry.CalculatMidPoint(curveToLoopIntersection);
								break;
							}
						}
					}
					if (xyz != null)
					{
						XYZ xyz2 = new XYZ(ptLand.X, ptLand.Y, 0.0);
						result = xyz - xyz2;
					}
				}
			}
			return result;
		}

		private void CreateAllDimension(StairsClearHeightMgr.DimObjType dimObjType, StairsClearHeightMgr.ClearHeightData srcCHData, StairsClearHeightMgr.ClearHeightData destCHData, ref List<DimesionDataManager> lstDimData, ElementId dimTypeId = null)
		{
			foreach (StairsClearHeightMgr.IntersectionData intersectionData in srcCHData.m_Intersection)
			{
				XYZ vecDimDir = null;
				Element element = this.m_doc.GetElement(intersectionData.m_InsectionId);
				if (element != null)
				{
					if (element.GetType() == typeof(StairsRun))
					{
						StairsRun stairsRun = element as StairsRun;
						if (stairsRun != null)
						{
							vecDimDir = this.GetStairsRunPath(stairsRun);
						}
					}
					else if (element.GetType() == typeof(StairsLanding))
					{
						StairsLanding stairsLanding = element as StairsLanding;
						if (stairsLanding != null)
						{
							vecDimDir = this.GetStairsLandDirection(stairsLanding, intersectionData.m_MaxMinPoint.m_ptMax);
						}
					}
					XYZ xyz = intersectionData.m_MaxMinPoint.m_ptMax;
					XYZ xyz2 = null;
					StairsRun stairsRun2 = null;
					foreach (StairsClearHeightMgr.IntersectionData intersectionData2 in destCHData.m_Intersection)
					{
						if (intersectionData.m_nGroupNum == intersectionData2.m_nGroupNum)
						{
							xyz2 = intersectionData2.m_MaxMinPoint.m_ptMin;
							if (dimObjType != StairsClearHeightMgr.DimObjType.DOT_LAND)
							{
								stairsRun2 = (this.m_doc.GetElement(intersectionData2.m_InsectionId) as StairsRun);
								break;
							}
							XYZ ptMin = intersectionData2.m_MaxMinPoint.m_ptMin;
							XYZ xyz3 = null;
							FamilyInstance famBeam = null;
							this.GetDimLandBeamsDepth(intersectionData2.m_InsectionId, out xyz3, out famBeam);
							if (xyz3 == null)
							{
								break;
							}
							xyz2 = null;
							bool bIsBottom = false;
							StairsRun stairsLandCutRun = this.GetStairsLandCutRun(intersectionData.m_InsectionId, ref bIsBottom);
							if (stairsLandCutRun == null)
							{
								break;
							}
							double disBeamToRun = this.GetDisBeamToRun(stairsLandCutRun, famBeam, bIsBottom);
							double d300Cmp = this.m_d300Cmp;
							if (disBeamToRun > d300Cmp)
							{
								xyz2 = xyz3;
								xyz = new XYZ(xyz3.X, xyz3.Y, xyz.Z);
								break;
							}
							break;
						}
					}
					if (xyz2 != null)
					{
						DimesionDataManager item = new DimesionDataManager(this.m_viewId, xyz, xyz2, dimTypeId, vecDimDir);
						lstDimData.Add(item);
						if (stairsRun2 != null)
						{
							StairsRun stairsRun3 = element as StairsRun;
							if (stairsRun3 != null)
							{
								this.Draw300MMDimension(stairsRun3, stairsRun2, xyz2, dimTypeId, ref lstDimData, true);
								this.Draw300MMDimension(stairsRun3, stairsRun2, xyz2, dimTypeId, ref lstDimData, false);
							}
						}
					}
				}
			}
		}

		public static void DeleteStairsClearHeightDimension(Autodesk.Revit.DB.Document doc, ElementId viewSectionId)
		{
			ViewSection viewSection = doc.GetElement(viewSectionId) as ViewSection;
			if (viewSection != null)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, viewSectionId);
				List<ElementId> list = filteredElementCollector.OfClass(typeof(Dimension)).ToElementIds().ToList<ElementId>();
				foreach (ElementId elementId in list)
				{
					Dimension dimension = doc.GetElement(elementId) as Dimension;
					if (dimension != null)
					{
						int num = StairsDimXDataMgr.ReadDimTypeXData(dimension);
						if (1 == num)
						{
							List<ElementId> list2 = StairsDimXDataMgr.ReadDimLineIdXData(dimension);
							doc.Delete(elementId);
							if (list2.Count > 0)
							{
								doc.Delete(list2);
							}
						}
					}
				}
			}
		}

		private double m_dRunTransValue = YJKArchMethodLibrary.Utils.Common.MMToFeet(1000.0);

		private double m_d300Cmp = YJKArchMethodLibrary.Utils.Common.MMToFeet(300.0);

		private Document m_doc;

		private ElementId m_viewId;

		private FloorSearchManager m_floorSearch;

		private double m_dTol;

		private StairsClearHeightMgr.InitDataType m_initDataType;

		private Dictionary<StairsClearHeightMgr.CheckType, List<List<StairsClearHeightMgr.ClearHeightData>>> m_checkData = new Dictionary<StairsClearHeightMgr.CheckType, List<List<StairsClearHeightMgr.ClearHeightData>>>();

		private Dictionary<StairsClearHeightMgr.DimObjType, List<List<StairsClearHeightMgr.ClearHeightData>>> m_dimensionData = new Dictionary<StairsClearHeightMgr.DimObjType, List<List<StairsClearHeightMgr.ClearHeightData>>>();

		public enum CheckType
		{
			CT_SRUN,
			CT_SLAND
		}

		public enum DimObjType
		{
			DOT_RUN,
			DOT_LAND
		}

		public enum InitDataType
		{
			INIT_CHKCLEARHEIGHT,
			INIT_DMSCLEARHEIGHT
		}

		public class CheckData
		{
			public CheckData(ElementId starisId, string sTip)
			{
				this.m_stairsId = starisId;
				this.m_sStdTip = sTip;
			}

			public ElementId m_stairsId { get; set; }

			public string m_sStdTip { get; set; }
		}

		private class MaxMinPoint
		{
			public MaxMinPoint()
			{
			}

			public MaxMinPoint(XYZ ptMin, XYZ ptMax)
			{
				this.m_ptMin = ptMin;
				this.m_ptMax = ptMax;
			}

			public XYZ m_ptMax { get; set; }

			public XYZ m_ptMin { get; set; }
		}

		private class IntersectionData
		{
			public IntersectionData(ElementId stairsId, ElementId insectionId, StairsClearHeightMgr.MaxMinPoint point, int nGroupNum)
			{
				this.m_StairsId = stairsId;
				this.m_InsectionId = insectionId;
				this.m_MaxMinPoint = point;
				this.m_nGroupNum = nGroupNum;
			}

			public ElementId m_StairsId { get; set; }

			public ElementId m_InsectionId { get; set; }

			public StairsClearHeightMgr.MaxMinPoint m_MaxMinPoint { get; set; }

			public int m_nGroupNum { get; set; }
		}

		private class ClearHeightData
		{
			public ClearHeightData(ElementId stairsId, List<StairsClearHeightMgr.IntersectionData> Intersections)
			{
				this.m_StairsId = stairsId;
				this.m_Intersection = Intersections;
			}

			public ElementId m_StairsId { get; set; }

			public List<StairsClearHeightMgr.IntersectionData> m_Intersection { get; set; }

			public double GetClearHDataMinZValue()
			{
				SortedSet<double> sortedSet = new SortedSet<double>();
				foreach (StairsClearHeightMgr.IntersectionData intersectionData in this.m_Intersection)
				{
					double z = intersectionData.m_MaxMinPoint.m_ptMin.Z;
					sortedSet.Add(z);
				}
				return sortedSet.First<double>();
			}
		}
	}
}
